#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, UILabelCountingMethod) {
    UILabelCountingMethodEaseInOut,
    UILabelCountingMethodEaseIn,
    UILabelCountingMethodEaseOut,
    UILabelCountingMethodLinear
};

typedef NSString* (^UICountingLabelFormatBlock)(double value);
typedef NSAttributedString* (^UICountingLabelAttributedFormatBlock)(double value);

/**
 *  原理 : 依靠CADisplayLink定时器（在每次刷新UI结束时都会被调用，跟屏幕刷新是同步的，精确度相当高），每次计算出当前的值（通过当前经过的时间/总动画的时间*最终value 得出），然后赋值，当赋值的时候会引起UI变化，这时又触发CADisplayLink定时器，依次循环，直到动画时间结束，释放定时器。
 */
@interface UICountingLabel : UILabel

/**
 *  浮点：@"%.2f"  整形：@"%d"
 */
@property (nonatomic, strong) NSString *format;


/**
 *  如果浮点数需要千分位分隔符,须使用@"###,##0.00"进行控制样式
 */
@property (nonatomic, strong) NSString *floatingPositiveFormat;

@property (nonatomic, assign) UILabelCountingMethod method;
@property (nonatomic, assign) NSTimeInterval animationDuration;

@property (nonatomic, copy) UICountingLabelFormatBlock formatBlock;
@property (nonatomic, copy) UICountingLabelAttributedFormatBlock attributedFormatBlock;
@property (nonatomic, copy) void (^completionBlock)();

-(void)countFrom:(double)startValue to:(double)endValue;
-(void)countFrom:(double)startValue to:(double)endValue withDuration:(NSTimeInterval)duration;

-(void)countFromCurrentValueTo:(double)endValue;
-(void)countFromCurrentValueTo:(double)endValue withDuration:(NSTimeInterval)duration;

-(void)countFromZeroTo:(double)endValue;
-(void)countFromZeroTo:(double)endValue withDuration:(NSTimeInterval)duration;

- (double)currentValue;

@end

